package vu.alfonsodiecko.stundenplanfhjena.gui;

import android.os.Bundle;

@SuppressWarnings("javadoc")
public abstract class ANotifyingScreenLoading extends ANotifyingScreen {

	private boolean progressEnd = false;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.actionbarsherlock.app.SherlockFragmentActivity#onPause()
	 */
	@Override
	protected void onPause() {
		super.onPause();

	}


	@Override
	protected void onResume() {
		super.onResume();

	}
	/**
	 * Funktion die daten im Hintergrungd laden tut und danach die Funktion
	 * createMainWindow() aufruft
	 * 
	 */
	public void startProgress() {
		
		Runnable runnable = new Runnable() {
			@Override
			public void run() {
				Runnable runnableGetData = new Runnable() {
					@Override
					public void run() {
						setProgressEnd(doInbackground());
					}
				};
				new Thread(runnableGetData).start();
				int i = 1;

				while (!isProgressEnd()) {

					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					setProgress();
					i++;
				}
				reloadGUI();
			}
		};
		new Thread(runnable).start();
	}
	
	abstract boolean doInbackground(); 
	abstract boolean reloadGUI(); 
	abstract boolean setProgress();; 
	/**
	 * @return the progressEnd
	 */
	public boolean isProgressEnd() {
		return progressEnd;
	}

	/**
	 * @param progressEnd the progressEnd to set
	 */
	public void setProgressEnd(boolean progressEnd) {
		this.progressEnd = progressEnd;
	}
}
